import { Component, OnInit } from '@angular/core';
import { BookAction, BookSelector } from '../../../store/book';
import { PageAction, PageSelector } from '../../../store/page';
import { Store } from '@ngxs/store';

@Component({
  selector: 'app-list',
  templateUrl: './list.component.html',
  styleUrls: ['./list.component.scss'],
})
export class ListComponent implements OnInit {

  books$ = this.store.select(BookSelector.list);
  page$ = this.store.select(PageSelector.page);

  constructor(
      private store: Store,
  ) {
  }

  ngOnInit(): void {
    this.store.dispatch([new PageAction.Reset(), new BookAction.RefreshData()]);
  }

  changePage($event: number) {
    this.store.dispatch([new PageAction.ChangeNo($event), new BookAction.RefreshData()]);
  }

}
